classdef masterClass < dynamicprops
    
    
   properties
      handles;
      stageONE
      stageTWO;
      stageTHREE;
      selectedFilter;
       
   end
   
   methods
       
       function master = masterClass(master)
           
           masterfig = hgload('masterGui.fig'); % load 'GUIDE generated' Figure.
           master.handles = guihandles(masterfig); % get figure handles.
           movegui(masterfig,'center');   % sets Figure position.
           
           set(master.handles.btn_create, 'callback', @master.btn_create_callback);
           set(master.handles.btn_customize, 'callback', @master.btn_customize_callback);
           set(master.handles.btn_implement, 'callback', @master.btn_implement_callback);
           
           master.selectedFilter = newFilter();
           
       end
       
       %%
       function btn_create_callback(master, varargin)
          
           master.stageONE = stageOne();
           
           
       end
       
       %%
       function btn_customize_callback(master, varargin)
           [~, filterID, ~] = getSelectedFilter(master.stageONE);
           filter = ['filter' num2str(filterID)];
           master.selectedFilter = master.stageONE.(filter);
           master.stageTWO = stageTwo(master.selectedFilter.filterPoles, master.selectedFilter.filterZeros, master.stageONE.template.filterType, master.stageONE.template.wa, master.stageONE.template.wp, master.stageONE.template.wpMAS, master.stageONE.template.wpMENOS, master.stageONE.template.waMAS, master.stageONE.template.waMENOS, sqrt(master.stageONE.template.wpMENOS*master.stageONE.template.wpMAS));          
           updateRemainingPolesList(master.stageTWO);
           updateRemainingZerosList(master.stageTWO);
           
       end
       
       %%
       function btn_implement_callback(master, varargin)
          
          master.stageTWO.finalFilter.transferFunction = master.stageTWO.finalFilter.filterGain * tf(1);
            
            for index = 1 : master.stageTWO.stageAmount
                stage = ['stage' num2str(master.stageTWO.stageTracking{index,1})];
                master.stageTWO.finalFilter.transferFunction = master.stageTWO.finalFilter.transferFunction * master.stageTWO.(stage).stageTransferFunction;
            end 
            
          master.stageTHREE = stageThree(master.stageTWO);
           
           
       end
       
       
       
   end
   
end